<?php
		
	/* SVN FILE: $Id: functions.php 43 2011-01-16 22:16:50Z andreoletti $ */
	
	/**
	* Project Name : arcadia
	*
	* @author $Author: andreoletti $
	* @version $Revision: 43 $
	* @lastrevision $Date: 2011-01-16 23:16:50 +0100 (dom, 16 gen 2011) $
	* @filesource $URL: http://svn.fletchlynd.com/arcadia/trunk/visioni/include/functions.php $
	*/

	include_once '../include/functions.php';


	/**
	 *
	 * fnFindLinked
	 *
	 */
	function fnFindLinked($iView)  {
	
		$aData = array();
		$html = '';
		
		global $sViewSelectFrom;
		global $sViewItemLink;
	
		// trovo tutte le autorizzazioni 'successive'
		$id = $iView;
		while ($id != 0)  {
			$sQuery = "SELECT * FROM `$sViewSelectFrom` WHERE `id`='$id' AND `iTrash`='0'";
			$rResult = custom_mysql_query($sQuery);
			if (mysql_num_rows($rResult) == 1) {
				$aRow = mysql_fetch_assoc($rResult);
				$aData[] = $aRow;
				if ($aRow['iRinnovo']==1 && $aRow['iViewRinnovo']!=0)  {
					$id = $aRow['iViewRinnovo'];
				} else  {
					$id = 0; 
				}
			} else {
				$id = 0; 
			}
		}
		
		$aData = array_reverse($aData); // inverto... in questo modo l'autorizzazione più 'nuova' sta all'inizio dell'array
	
		// trovo tutte le autorizzazioni 'precedenti'
		$id = $iView;
		while ($id != 0)  {
			$sQuery = "SELECT * FROM `$sViewSelectFrom` WHERE `iRinnovo`='1' AND `iViewRinnovo`='$id' AND `iTrash`='0'";
			$rResult = custom_mysql_query($sQuery);
			if (mysql_num_rows($rResult) == 1) {
				$aRow = mysql_fetch_assoc($rResult);
				$aData[] = $aRow;
				$id = $aRow['id'];;
			} else {
				$id = 0; 
			}
		}	
	
		if (count($aData)>1) {
			$html .= "<div class='history'>";
			foreach ($aData as $aRow)  {
				if (!empty($aRow))  {
					$sProtocollo = (!empty($aRow['sProtocollo']) ? 'Prot. '.$aRow['sProtocollo'] : 'Scheda Prova Visione');
					$sProtocollo .= (!empty($sProtocollo) && $aRow['dtProtocollo']!='0000-00-00' ? ' del '.date_convert($aRow['dtProtocollo'],'html') : '');
					$dtScadenza = ($aRow['dtScadenza']!='0000-00-00' ? 'Scad: '.date_convert($aRow['dtScadenza'],'html') : '');
					$html .= "<li ".($iView == $aRow['id'] ? " class='selected' " : "").">".
						($iView != $aRow['id'] ? "<a href='./$sViewItemLink?iView=".$aRow['id']."'>" : "<strong>").
						"$sProtocollo".
						(!empty($dtScadenza) ? "&nbsp;$dtScadenza" : '').($iView != $aRow['id'] ? "</a>" : "</strong>")."</li>";
				}
			}
			$html .= "</div>";
		}
		return $html;
	}
	
	
	
	
		
		
	function sendMail($view_id, $data, $to, $template, $edit_allowed=1) {
		global $action;
		global $DEBUG_MSG;
		
		$html = '';
		$allowed = edit_allowed('email_aagg');
		
		if ($data['data_verifica']!='0000-00-00' && $data['esito_verifica']=='1')  {
			if ($data['email_aagg']!='0000-00-00 00:00:00') {
				if  ($action != 'edit' && $allowed && $edit_allowed) {
			
					$html .= "<form method='get' name='sendmail' action='sendmail2.php'>".
						"<input type='hidden' name='view_id' id='view_id' value='$view_id'>".
						"<input type='hidden' name='to' id='to' value='$to'>".
						"<input type='hidden' name='template' id='template' value='$template'>".
						"<input type='button' name='send' id='send' value='Invia Mail AAGG' onClick='this.form.submit()'>".
						"</form>";
				}
			} else {
				$html .= "";
			}
		} else {
			$html .= "&nbsp;"; 
		}
		return $html;
		
	}




?>
